<template>
  <div>
    <div class="user">
      <!-- 基本信息 -->
      <div class="user-profile">
        <div class="info">
          <van-image round :src="userInfo.photo" />
          <h3 class="name">
            {{ userInfo.name }}
            <br />
            <van-tag size="mini">{{ userInfo.birthday }}</van-tag>
          </h3>
        </div>
      </div>

      <!-- 操作链接 -->
      <van-row class="user-links">
        <van-col span="8">
          <van-icon name="newspaper-o" color="#7af" />
          我的作品
        </van-col>
        <van-col span="8">
          <van-icon name="star-o" color="#f00" />
          我的收藏
        </van-col>
        <van-col span="8">
          <van-icon name="tosend" color="#fa0" />
          阅读历史
        </van-col>
      </van-row>

      <!-- 编辑入口 -->
      <van-cell-group class="user-group">
        <van-cell icon="edit" to="/edit" title="编辑资料" is-link />
        <van-cell
          icon="chat-o"
          title="小智同学"
          is-link
          @click="$router.push('/xiaozhi')"
        />
        <van-cell icon="setting-o" title="系统设置" is-link />
        <van-cell icon="warning-o" title="退出登录" is-link />
      </van-cell-group>
    </div>
  </div>
</template>

<script>
import { getUser } from '@/api/user'
import { mapState } from 'vuex'
export default {
  data() {
    return {
      userInfo: {}
    }
  },
  computed: {
    ...mapState([''])
  },
  async created() {
    try {
      const result = await getUser()
      this.userInfo = result.data
      // console.log(this.userInfo)
    } catch (e) {
      this.$router.push('/login')
    }
  }
}
</script>

<style lang="less" scope>
.user {
  &-profile {
    width: 100%;
    height: 100px;
    display: block;
    background: #3296fa;
    color: #fff;
    .info {
      display: flex;
      padding: 20px;
      align-items: center;
      .van-image {
        width: 64px;
        height: 64px;
      }
      .name {
        font-size: 16px;
        font-weight: normal;
        margin-left: 10px;
      }
      .van-tag {
        background: #fff;
        color: #3296fa;
      }
    }
    p {
      margin: 0;
      text-align: center;
    }
  }

  &-links {
    padding: 15px 0;
    font-size: 12px;
    text-align: center;
    background-color: #fff;
    .van-icon {
      display: block;
      font-size: 24px;
      padding-bottom: 5px;
    }
  }
}
</style>
